#ifndef __BFIFO_H
#define __BFIFO_H

#include "common.h"

typedef struct _bfifo {
    uint8_t *buf;
    uint16_t ptr_in, ptr_out;
    uint16_t mask, len;
} bfifo_t, *pbfifo_t;

void bfifo_init(pbfifo_t f, uint8_t *buff, uint16_t size);

static __inline uint16_t bfifo_avail(pbfifo_t f)
{
    return f->len - (f->ptr_in - f->ptr_out);
}

static __inline uint16_t bfifo_len(pbfifo_t f)
{
    return f->ptr_in - f->ptr_out;
}

void bfifo_in_byte(pbfifo_t f, uint8_t b);
bool bfifo_out_byte(pbfifo_t f, uint8_t *b);
int bfifo_in(pbfifo_t f, const void *src, uint16_t len);
int bfifo_out(pbfifo_t f, void *dst, uint16_t len);

void bfifo_reset(pbfifo_t f);

#endif  // __BFIFO_H
